package Operate;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class ReturnOperate implements IOOperate{
    @Override
    public void work(BookList bookList) {
        System.out.println("Return");
        System.out.println("book-name:");
        Scanner scanner = new Scanner(System.in);
        String bookName = scanner.nextLine();

        int bookSize = bookList.getBookNumber();
        for (int i = 0; i < bookSize; i++) {
            //获得书籍信息
            Book book = bookList.getBook(i);
            //对比书籍名称
            if(bookName.equals(book.getName())){
                if(book.isBorrowed()){
                    System.out.println("return");
                    book.setBorrowed(false);
                }else {
                    System.out.println("can't return");
                }
                return;
            }
        }
    }
}
